home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JSplitPane;
- import com.sun.java.swing.UIManager;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Cursor;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.io.Serializable;
- import java.util.EventObject;
-
- public class BasicSplitPaneDivider extends Container implements PropertyChangeListener, Serializable {
- protected static final int ONE_TOUCH_SIZE = 5;
- protected static final int ONE_TOUCH_OFFSET = 2;
- protected DragController dragger;
- protected BasicSplitPaneUI splitPaneUI;
- protected int dividerSize = 0;
- protected Component hiddenDivider;
- protected JSplitPane splitPane;
- protected MouseHandler mouseHandler;
- protected int orientation;
- protected JButton leftButton;
- protected JButton rightButton;
- static final Cursor horizontalCursor = Cursor.getPredefinedCursor(11);
- static final Cursor verticalCursor = Cursor.getPredefinedCursor(9);
- static final Cursor defaultCursor = Cursor.getPredefinedCursor(0);
-
- public BasicSplitPaneDivider(BasicSplitPaneUI ui) {
- ((Container)this).setLayout(new DividerLayout(this));
- this.setBasicSplitPaneUI(ui);
- this.orientation = this.splitPane.getOrientation();
- ((Component)this).setBackground(UIManager.getColor("SplitPane.background"));
- }
-
- protected JButton createLeftOneTouchButton() {
- JButton b = new 1(this);
- ((AbstractButton)b).setFocusPainted(false);
- ((AbstractButton)b).setBorderPainted(false);
- return b;
- }
-
- protected JButton createRightOneTouchButton() {
- JButton b = new 2(this);
- ((AbstractButton)b).setFocusPainted(false);
- ((AbstractButton)b).setBorderPainted(false);
- return b;
- }
-
- protected void dragDividerTo(int location) {
- this.splitPaneUI.dragDividerTo(location);
- }
-
- protected void finishDraggingTo(int location) {
- this.splitPaneUI.finishDraggingTo(location);
- }
-
- public BasicSplitPaneUI getBasicSplitPaneUI() {
- return this.splitPaneUI;
- }
-
- public int getDividerSize() {
- return this.dividerSize;
- }
-
- public Dimension getPreferredSize() {
- return new Dimension(this.getDividerSize(), this.getDividerSize());
- }
-
- protected void oneTouchExpandableChanged() {
- if (this.splitPane.isOneTouchExpandable() && this.leftButton == null && this.rightButton == null) {
- this.leftButton = this.createLeftOneTouchButton();
- if (this.leftButton != null) {
- this.leftButton.addActionListener(new LeftActionListener(this));
- }
-
- this.rightButton = this.createRightOneTouchButton();
- if (this.rightButton != null) {
- this.rightButton.addActionListener(new RightActionListener(this));
- }
-
- if (this.leftButton != null && this.rightButton != null) {
- ((Container)this).add(this.leftButton);
- ((Container)this).add(this.rightButton);
- }
- }
-
- ((Container)this).invalidate();
- ((Container)this).validate();
- }
-
- public void paint(Graphics g) {
- super.paint(g);
- }
-
- protected void prepareForDragging() {
- this.splitPaneUI.startDragging();
- }
-
- public void propertyChange(PropertyChangeEvent e) {
- if (((EventObject)e).getSource() == this.splitPane) {
- if (e.getPropertyName().equals("orientation")) {
- this.orientation = this.splitPane.getOrientation();
- ((Container)this).invalidate();
- ((Container)this).validate();
- } else if (e.getPropertyName().equals("oneTouchExpandable")) {
- this.oneTouchExpandableChanged();
- }
- }
-
- }
-
- public void setBasicSplitPaneUI(BasicSplitPaneUI newUI) {
- if (this.splitPane != null) {
- this.splitPane.removePropertyChangeListener(this);
- if (this.mouseHandler != null) {
- this.splitPane.removeMouseListener(this.mouseHandler);
- this.splitPane.removeMouseMotionListener(this.mouseHandler);
- this.mouseHandler = null;
- }
- }
-
- this.splitPaneUI = newUI;
- if (newUI != null) {
- this.splitPane = newUI.getSplitPane();
- if (this.splitPane != null) {
- if (this.mouseHandler == null) {
- this.mouseHandler = new MouseHandler(this);
- }
-
- this.splitPane.addMouseListener(this.mouseHandler);
- this.splitPane.addMouseMotionListener(this.mouseHandler);
- this.splitPane.addPropertyChangeListener(this);
- if (this.splitPane.isOneTouchExpandable()) {
- this.oneTouchExpandableChanged();
- }
- }
- } else {
- this.splitPane = null;
- }
-
- }
-
- public void setDividerSize(int newSize) {
- this.dividerSize = newSize;
- }
- }
-